﻿using EMoney.IStock.Client.Models.Yjjx;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace EMoney.IStock.Client.DataAccess.Yjjx
{
    /// <summary>
    /// 业绩精选数据访问类
    /// </summary>
    public class YjjxDal
    {
        /// <summary>
        /// 获取入选期间去重后股票个数
        /// </summary>
        /// <param name="blType"></param>
        /// <returns></returns>
        public int GetInStockCount(string blType)
        {
            string sql = "SELECT  COUNT(DISTINCT SecuCode) FROM VM_PERFORMANCE_CHANGE_POOL WHERE BLType=@BLType";

            SQLTools tools = new SQLTools();
            tools.AddSqlParameter("BLType", System.Data.SqlDbType.VarChar, 20, blType);

            return Convert.ToInt32(SQLHelper.ExecuteScalar(ConnectionManager.Fplat, System.Data.CommandType.Text, sql, tools.GetSqlParameters()));
        }

        /// <summary>
        /// 获取入选期间股票最大收益大于10的个数
        /// </summary>
        /// <param name="blType"></param>
        /// <returns></returns>
        public int GetInStockLChangeRatioCount(string blType)
        {
            string sql = "SELECT count(DISTINCT SecuCode) FROM VM_PERFORMANCE_CHANGE_POOL WHERE  BLType=@BLType and  LChangeRatio>5";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("BLType", System.Data.SqlDbType.VarChar, 20, blType);

            return Convert.ToInt32(SQLHelper.ExecuteScalar(ConnectionManager.Fplat, System.Data.CommandType.Text, sql, tools.GetSqlParameters()));
        }

        /// <summary>
        /// 获取业绩精选战绩数据
        /// </summary>
        /// <returns></returns>
        public List<VM_PERFORMANCE_CHANGE_POOL_GOODRATIO> GetRecord()
        {
            string sql = "SELECT SecuCode,SecuAbbr,InDate,BLType,LChangeRatio,CONVERT(VARCHAR(10),InDate,120) StrInDate FROM VM_PERFORMANCE_CHANGE_POOL_GOODRATIO ORDER BY lchangeratio DESC";

            return SQLHelper.GetDataByColumnsLst<VM_PERFORMANCE_CHANGE_POOL_GOODRATIO>(ConnectionManager.Fplat, sql, null);
        }

        /// <summary>
        /// 获取业绩精选统计信息
        /// </summary>
        /// <param name="tradeDate"></param>
        /// <returns></returns>
        public PERFORMANCE_Change_Stat GetStat(DateTime tradeDate)
        {
            string sql = "SELECT * FROM PERFORMANCE_Change_Stat WHERE TradeDate=@TradeDate";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("TradeDate", SqlDbType.DateTime, tradeDate);

            return SQLHelper.GetDataByColumns<PERFORMANCE_Change_Stat>(ConnectionManager.Fplat, sql, tools.GetSqlParameters());
        }

        /// <summary>
        /// 获取业绩精选股票池
        /// </summary>
        /// <param name="inDate">入选日期</param>
        /// <returns></returns>
        public List<VM_PERFORMANCE_CHANGE_POOL_MAXDATE> GetPool(DateTime inDate)
        {
            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("ToDay", SqlDbType.DateTime, inDate);

            return SQLHelper.GetProcedureDataByColumnsLst<VM_PERFORMANCE_CHANGE_POOL_MAXDATE>(ConnectionManager.Fplat, "SP_PERFORMANCE_CHANGE_POOL_VIADAY", tools.GetSqlParameters());
        }
    }
}
